package com.primeton.eos.oss.model.controller;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eos.foundation.ScheduleInfo;
import com.eos.foundation.eoscommon.ScheduleUtil;
import com.eos.foundation.impl.ScheduleInfoImpl;
import com.eos.system.utility.PageResultList;
import com.primeton.eos.api.springboot.EOS8ApplicationContext;
import com.primeton.eos.oss.model.result.SuccessResult;
import com.primeton.eos.oss.model.service.ThirdSynDataService;

import commonj.sdo.DataObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 单点系统数据同步
 * @author hudaheng
 *
 */
@Api(tags = "单点数据同步管理")
@RestController
@RequestMapping("/api/oss/thirdSynData")
public class ThirdSynDataController {
	
	@Autowired
	ThirdSynDataService thirdSynDataService;
	
	public final static String CRONEXPRESSION = EOS8ApplicationContext.INSTANCE.getProperty("syn_cron_time");
	
	
	@ApiOperation("同步用户数据")
    @GetMapping("/loadUser")
	public String loadUser() throws IOException {
		thirdSynDataService.loadUser();
		return new SuccessResult().toJSONString();
	}
	
	
	@ApiOperation("处理组织机构数据")
    @GetMapping("/dealOrgStructure")
	public String dealOrgStructure() throws IOException {
		thirdSynDataService.dealOrgStructure();
		return new SuccessResult().toJSONString();
	}
	
	
	@ApiOperation("定时任务")
    @GetMapping("/dealTask")
	public String dealTask() throws IOException {
		Map map =ScheduleUtil.get("default", "dealTask1");
		if(null==map) {
			ScheduleInfo scheduleInfo=new ScheduleInfoImpl();
			scheduleInfo.setTaskName("dealTask1");
			scheduleInfo.setTargetQName("com.primeton.eos.oss.model.controlle.loadUser");
			scheduleInfo.setTargetOperation("loadUser");
			scheduleInfo.setArgs(new ArrayList<Object>());
			scheduleInfo.setIsStateful(false);
			scheduleInfo.setCronExpression("*/5 * * * * *");
			ScheduleUtil.add(scheduleInfo);
		}else {
			ScheduleInfo scheduleInfo=(ScheduleInfo) map.get("dealTask");
			scheduleInfo.setCronExpression(CRONEXPRESSION);
			ScheduleUtil.update(scheduleInfo);
		}
		return new SuccessResult().toJSONString();
	}
	
	
	


}
